<?php
/**
 * Description of PrettyPhotoWidget
 * source: http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone
 * @author vzangloo
 */
class PrettyPhotoWidget extends CWidget {
    
    public $selector='#prettyPhoto';
    public $options=array();
    private $_assetsUrl;

    public function init() {
        parent::init();
        if ($this->_assetsUrl === null) {
            $assetsDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
            $this->_assetsUrl = Yii::app()->assetManager->publish($assetsDir);
        }
    }
    
    public function run(){
        $this->options=empty($this->options)? '': CJSON::encode($this->options);
            
        Yii::app()->clientScript
                ->registerCssFile($this->_assetsUrl.'/css/prettyPhoto.css')
                ->registerScriptFile($this->_assetsUrl.'/js/jquery.prettyPhoto.js')
                ->registerScript(__CLASS__,'
                    $(document).ready(function(){
                       $("'.$this->selector.'").prettyPhoto('.$this->options.'); 
                    });
                ', CClientScript::POS_END);
    }
}
